/*
 * @(#)GSBaseDAO.java 
 * 
 * Project: BUS
 * 
 * Modify Information:
 * =============================================================================
 * Author        Date            Description 
 * Simonyi       2005-12-03      first release 
 * Jenny Li      2006-01-20      修改操作员姓名从DB中取得
 * 
 * Copyright Notice:
 * =============================================================================
 * Copyright (c) 2001-2005 Beijing HiTRUST Technology Co., Ltd. 1808 Room,
 * Science & Technology Building, No. 9 South Street, Zhong Guan Cun, Haidian
 * District, Beijing ,100081, China All rights reserved.
 * 
 * This software is the confidential and proprietary information of Beijing
 * HiTRUST Technology Co., Ltd. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in accordance
 * with the terms of the license agreement you entered into with HiTRUST.
 * 
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.bean.GSFunctionBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.*;
import com.hitrust.gs.dao.GSFunctionDAO;
import com.hitrust.gs.dao.GSOperatorDAO;
/**
 * @author simonyi
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GSOperatorFuncResetInitAction extends GSBaseAction {

    public String execute(GSBaseForm aForm) throws Exception {
        
        GSOperatorBean operatorBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        
        GSOperatorProcessor proc = new GSOperatorProcessor ();
        GSOrganizationProcessor orgp = new GSOrganizationProcessor();

        GSFunctionDAO fdao = new GSFunctionDAO();
        ArrayList buf = fdao.getFunctionsNotLabel();
        ArrayList ary1 = new ArrayList();//运营公司菜单
        ArrayList ary2 = new ArrayList();//巴士物资菜单
        for(int i=0;i<buf.size();i++){
            GSFunctionBean fBean = (GSFunctionBean)buf.get(i);
            if(fBean.getGs_func_appurtenant().equals("1")){
                ary2.add(fBean);
            }else if(fBean.getGs_func_appurtenant().equals("0")){
                ary1.add(fBean);
            }else if(fBean.getGs_func_appurtenant().equals("2")){
                ary2.add(fBean);
                ary1.add(fBean);
            }
        }
//        aForm.getRequest().setAttribute("ary1",ary1);
//        aForm.getRequest().setAttribute("ary2",ary2);

        HashMap map = new HashMap();

        String operId = aForm.getRequest().getParameter("operid");
//        String operName = aForm.getRequest().getParameter("opername");
        GSOperatorBean tOper = new GSOperatorDAO().queryOperById(operId);
        String operName = tOper.getGs_oper_name();
        
        if(tOper.getGs_oper_org_id().substring(0,2).equals("00")){
            aForm.getRequest().setAttribute("ary2",ary2);    
        }else{
            aForm.getRequest().setAttribute("ary1",ary1);
        }

        ArrayList currary = proc.getOperPrivilege(operId);
        if(currary != null )
	        for(int i=0;i<currary.size();i++){
                String temp = (String)currary.get(i);
	            map.put(temp,temp);
            }
        aForm.getRequest().setAttribute("currary",map);
        aForm.getRequest().setAttribute("operid",operId);
        aForm.getRequest().setAttribute("opername",operName);
        
        return GSBaseConstants.FORWARD_SUCCESS;
    }
}
